#!/usr/bin/env python3
from counter import Counter
from floatwindow import FloatWindow
from nicegui.element import Element
from nicegui import ui, app
from pathlib import Path

folder = Path(__file__).resolve().parent / 'images'
app.add_static_files('/images', folder)  # serve all files in this folder


ui.markdown('''
#### Try the new click counter!

Click to increment its value.
''')
# with ui.card().classes("fixed bolder-solid bolder-2 bolder-sky-500 bg-lime-200 z-[1100]"):
with ui.card():
    counter = Counter('Clicks', on_change=lambda e: ui.notify(f'The value changed to {e.args}.'))
    ui.label("Hello, world!").classes("bg-light rounded rounded")

# with FloatWindow('浮动窗口演示', content="This is a float window Demo, just show ..."):
#     ui.image('/images/cat_card.png').classes('w-full h-[320px]')

fw:FloatWindow = None

def promtWindow():
    counter = 0
    def showit():
        global fw
        nonlocal counter
        counter += 1
        if fw is None:
            with (fw := FloatWindow(f'浮动窗口演示-{counter}', content=f'<span style="color: red">This is a float window Demo{counter}</span>, just show ...')):
                 ui.label("1. xxxxx")
                 ui.image('/images/cat_card.png').classes('min-w-full h-[320px] resize')
        else:
            fw.updateTitle(f'浮动窗口演示-{counter}')
            if counter == 4:
                fw.updateContent()
            else:
                fw.updateContent(f'<span style="color: red">This is a float window Demo{counter}</span>, just show ...')
            fw.update()
    return showit



ui.button('Reset', on_click=counter.reset).props('small outline')
with ui.card():
    ui.button("FloatWindow", on_click=promtWindow()).props('small outline')
    with ui.row():
        ui.button("Hide", on_click=lambda:fw.hide())
        ui.button("Show", on_click=lambda:fw.show())

ui.run()
